package com.zixuan.sina.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zixuan.sina.dao.TopicMapper;
import com.zixuan.sina.entity.Topic;
import com.zixuan.sina.service.TopicService;
import com.zixuan.sina.utils.Result;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements TopicService {

    @Override
    public    List<Topic>  getTopicsByPostId(String postId) {
        return baseMapper.getTopicsByPostId(postId);
    }

    @Override
    public Result listTopic(Topic topic) {
        QueryWrapper<Topic> wrapper=new QueryWrapper<>();
        if(!StringUtils.isBlank(topic.getTopicStr())){
            wrapper.like("topicStr",topic.getTopicStr());
        }
        List<Topic> topics = baseMapper.selectList(wrapper);
        return Result.ok(topics);
    }

    @Override
    public void addPostTopic(String postId, List<Long> topicIds) {
        baseMapper.addPostTopic(postId,topicIds);
    }
}
